package com.sicau.basedemo.common.returning;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 返回数据格式定义
 */
@Data
@Accessors(chain = true)
@ApiModel(value = "统一返回对象", description = "请求结果无论成功与否,都将返回此对象，请求结果将展现在其中")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResultData<T> {

    /**
     * 返回信息
     */
    @ApiModelProperty(name = "返回信息")
    private String resultIns;

    /**
     * 返回状态
     */
    @ApiModelProperty(name = "返回状态")
    private String resultStatus;

    /**
     * 返回对象
     */
    @ApiModelProperty(name = "返回对象")
    private T obj;

    public ResultData() {
    }

    public ResultData<T> OK() {
        this.resultIns = ResultStatus.SUCCESS.getIns();
        this.resultStatus = ResultStatus.SUCCESS.getStatus();
        return this;
    }

    public ResultData<T> FAILED() {
        this.resultIns = ResultStatus.FAILED.getIns();
        this.resultStatus = ResultStatus.FAILED.getStatus();
        return this;
    }

    public ResultData<T> NOT_MATCH() {
        this.resultIns = ResultStatus.NOT_MATCH.getIns();
        this.resultStatus = ResultStatus.NOT_MATCH.getStatus();
        return this;
    }

    public ResultData(String resultIns, String resultStatus, T obj) {
        this.resultIns = resultIns;
        this.resultStatus = resultStatus;
        this.obj = obj;
    }

    public ResultData(String resultIns, String resultStatus) {
        this.resultIns = resultIns;
        this.resultStatus = resultStatus;
    }

}